package shapes;

import java.util.Arrays;
import java.util.Scanner;

class PersonSortable implements Comparable<PersonSortable> {
	private String name;
	private int age;
	

	public PersonSortable(String name, int age) {
		this.name = name;
		this.age = age;
		
	}

	public int compareTo(PersonSortable s) {
		
			if (this.name.compareTo(s.name) == 0) {
				return this.age > s.age ? 1 : -1;
			}
			return this.name.compareTo(s.name);
		}
	

	@Override
	public String toString() {
		return this.name + "-" + this.age ;
	}
}

public class Main {
	public static void main(String[] args) {
		Scanner cin = new Scanner(System.in);
		// student s=new student();
		while (cin.hasNextInt()) {
			int n = cin.nextInt();
			PersonSortable[] s = new PersonSortable[n];
			for (int i = 0; i < n; i++) {
				s[i] = new PersonSortable(cin.next(), cin.nextInt());
			}
			Arrays.sort(s);
			for (PersonSortable t : s) {
				System.out.println(t);
			}
System.out.println(Arrays.toString(PersonSortable.class.getInterfaces()));
		}
	}
}